const virtualbank = {
    namespaced: true,
    state: () => ({  
        tabledata: [],
        showmodal: false,
        title: '',
        creatrouter: '',
        editrouter: '',
        fullscreen: false,
        tablecolumns: []
    }),
    mutations: { 
        UPDATE_TABLE_COLUMNS: (state,payload) => {
            //console.log(payload)
            payload = [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    type: 'index',
                    key: 'Index',
                    title: '序号',
                    width: 80,
                    align: 'center'
                },
                {
                    title: '虚拟银行账户',
                    key: 'BankAccount'
                },
                {
                    title: '虚拟号',
                    key: 'VirtualAccount'
                },
                {
                    title: '项目',
                    key: 'ProjectItem'
                }
            ]
            state.tablecolumns = payload;
        },
        UPDATE_TABLE_DATA: (state,payload) => {
            //console.log(payload)
            payload = [
                {
                    VirtualBankGuid: 'dfdfdfdfdfddfdfd',
                    VirtualBankName: 'John Brown1',
                    BankAccount: 18,
                    AccountType: 'New York No. 1 Lake Park'
                }
            ];
            state.tabledata = payload;
        },
        CHANGE_TITLE: (state,payload) => {
            state.title = payload;
        },
        CHANGE_MODAL: (state) => {
            state.showmodal = !state.showmodal;
        },
        SETTING_CREATROUTER: (state,payload) => {
            state.creatrouter = payload;
        },
        SETTING_EDITROUTER: (state,payload) => {
            state.editrouter = payload;
        },
        CREATE:(state,payload) => {
            state.tabledata.push(payload)
        },
        DELETE:(state,payload) => {
            for(var item in payload){
                let index = state.tabledata.findIndex(removeItem => removeItem.AccountGuid === item.Guid)
                state.tabledata.splice(index,1)
            }
        },
        UPDATE:(state,payload) => {
            console.log('发送数据至服务器修改');
            console.log(payload);
            let index = state.tabledata.findIndex(item => item.AccountGuid === payload.Guid);
            state.tabledata.splice(index,1,payload)
        }
    },
    actions: {
        InitVirtualBank({commit},payload){
            commit('SETTING_CREATROUTER',payload.CreatRouter)
            commit('SETTING_EDITROUTER',payload.EditRouter)
            //console.log(payload)
            commit('UPDATE_TABLE_DATA',payload.TableData);
            commit('UPDATE_TABLE_COLUMNS',payload.TableColumns);
        },
        CreateView({commit}){
            commit('CHANGE_TITLE',"创建虚拟银行信息")
            commit('CHANGE_MODAL');
        },
        CreateAsync({commit},payload){
            commit('CREATE',payload)
        },
        UpdateView({commit}){
            commit('CHANGE_TITLE',"编辑虚拟银行信息")
            commit('CHANGE_MODAL');
        },
        UpdateAsync({commit},payload){
            /* setTimeout(() => {
                
            }, 1000) */
            commit('UPDATE_TABLE_DATA',payload)
        },
        Create({commit},payload){
            commit('CREATE',payload)
        },
        Delete({commit},payload){
            commit('DELETE',payload)
        },
        Update({commit},payload){
            commit('UPDATE',payload)
        }
    },
    getters: { 
        tablecolumns: state => state.tablecolumns,
        tabledata: state => state.tabledata,
        showmodal: state => state.showmodal,
        /* creatrouter: state => state.creatrouter,
        editrouter: state => state.editrouter */
    }
}

export default virtualbank